﻿#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    timer = new QTimer;

    QImage img;
    img.load("d:\\Pictures\\Saved Pictures\\1.jpg");
    ui->label->setPixmap(QPixmap::fromImage(img)) ;

    //定时器时间到了,发出TIMEOUT信号
    connect(timer,&QTimer::timeout,this, &Widget::timeoutSlot);

    picId = 1;

}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    timer->start(TIMEROUT);
}

void Widget::timeoutSlot(){
    QString path("d:\\Pictures\\Saved Pictures\\");
    path+=QString::number(picId);
    path+= ".jpg";
    QImage img;
    img.load(path);
    ui->label->setPixmap(QPixmap::fromImage(img));

    picId++;
    if(5 == picId){
        picId = 1;
     }
}



void Widget::on_pushButton_2_clicked()
{
    timer->stop();
}


void Widget::on_pushButton_3_clicked()
{
    QTimer::singleShot(1000, this, SLOT(timeoutSlot()));
}

